package com.kk.travel.service;

import java.util.List;

import com.kk.travel.admin.User;
import com.kk.travel.admin.Word;
import com.kk.travel.dao.UserDao;
import com.kk.travel.dao.WordDao;
import com.kk.travel.dao.impl.UserDaoImpl;
import com.kk.travel.dao.impl.WordDaoImpl;

public class UserService {
	private UserDao userdao=new UserDaoImpl();
	private WordDao wordDao=new WordDaoImpl();
	
	public void updateWordCount(Integer id,Integer count){
		wordDao.updateClickCount(id, count);
	}
	
    public List<Word> getWords(){
    	return wordDao.getAllWords();
    }
	
	public void speak(String email,String word,String time){
		wordDao.insertWord(email, word,time);
	}
	
	/**
	 * 
	 *	增加user		
	 * @param user
	 * @return
	 */
	public void InsertUser(User user){
		userdao.InsertUser(user);
	}
	
	/**
	 * 
	 *	根据id返回user
	 *
	 * @param id
	 * @return
	 */
	public User getUserById(Integer id){
		return userdao.getUserById(id);
	}
	/**
	 * 
	 *根据id删除user
	 *
	 * @param id
	 */
	public void deleteUserById(Integer id){
		userdao.deleteUserByid(id);
	}
	/**
	 * 修改user
	 */
	public void modifyUser(User user){
		userdao.ModifyUserById(user);
	} 
	
	/**
	 * 验证用户名（email）是否存在
	 * @param name
	 * @param mail
	 * @return
	 */
	public String result(String name,String mail){
		String result="0";
		Integer id=userdao.getNameOrEmail(name, mail);
		if(id==null){
			result="1";
		}
		
		return result;
	}
	
	/**
	 * 验证账号密码（数据库是否存在）
	 * @param user
	 * @return
	 */
	public User validateUser(User user){
		User user2=userdao.getUser(user);	
		if(user2!=null){
			return user2;
		}		
		return null;
	}

}
